package cn.tedu.egmvc1.base.exception;

import cn.tedu.egmvc1.base.response.JsonResult;
import cn.tedu.egmvc1.base.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult doHandle(IllegalArgumentException ex){
        String data=ex.getMessage();
        log.error("IllegalArgumentException:{}",data);
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    @ExceptionHandler
    public JsonResult dohandlerThrowable(Throwable ex){
        String data=ex.getMessage();
        log.error("Throwable:{}",data);
        return new JsonResult(StatusCode.THROWABLE_ERROR,data);
    }
}
